package LeetCode;

public class No543 {
    public static void main(String[] args) {

    }
    private int max = 0;
    public static int diameterOfBinaryTree(TreeNode root) {
        int[] max ={0};
        getNode(root,max);
        return max[0];
    }

    public static int getNode(TreeNode node,int[] max){
        if(node == null) return -1;
        int left = getNode(node.left,max)+1;
        int right = getNode(node.right,max)+1;
        if(max[0]<left+right) max[0] = left+right;
        return Math.max(left,right);
    }

}
